﻿using System;
using System.Collections.Generic;
using System.Text;

namespace _2022Learning.Iterator
{
    /// <summary>
    /// Get访问器使用yield return 语句
    /// 下一次循环会从上次yield return 后的下一句开始执行；
    /// </summary>
    public class GetAccessor
    {
        public static IEnumerable<int> Show(int x)
        {
            for (int a = 0, b = 0, c = 1; a < x; a++)
            {
                yield return b;
                int temp = b + c;
                b = c;
                c = temp;
            }
        }

        public class Days
        {
            public IEnumerable<Day> DaysOfWeek
            {
                get
                {
                    yield return new Day { DayName = "Sunday", DayOfWeek = 1 };
                    yield return new Day { DayName = "Monday", DayOfWeek = 2 };
                    yield return new Day { DayName = "Tuesday", DayOfWeek = 3 };
                    yield return new Day { DayName = "Wednesday", DayOfWeek = 4 };
                    yield return new Day { DayName = "Thursday", DayOfWeek = 5 };
                    yield return new Day { DayName = "Friday", DayOfWeek = 6 };
                    yield return new Day { DayName = "Saturday", DayOfWeek = 7 };
                }
            }
        }

        public class Day
        {
            public string DayName
            { get; set; }
            public int DayOfWeek
            { get; set; }
        }
    }
}
